package com.abcode.nettyserversocketio.gen.controller;


import com.abcode.nettyserversocketio.common.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

import com.abcode.nettyserversocketio.gen.entity.FriendRequest;
import com.abcode.nettyserversocketio.gen.service.FriendRequestService;


/**
 * 申请好友(FriendRequest)表控制层
 *
 * @author abcode
 * @since 2023-06-19 22:45:38
 */
@RestController
@RequestMapping("friendRequest")
public class FriendRequestController {
    /**
     * 服务对象
     */
    @Resource
    private FriendRequestService friendRequestService;

    /**
     * 分页查询所有数据
     *
     * @param page          分页对象
     * @param friendRequest 查询实体
     * @return 所有数据
     */
    @GetMapping("/selectAll")
    public Result selectAll(Page<FriendRequest> page, FriendRequest friendRequest) {
        Page<FriendRequest> rst = this.friendRequestService.page(page, new QueryWrapper<>(friendRequest));
        return Result.ok(rst);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne/{id}")
    public Result selectOne(@PathVariable Serializable id) {
        FriendRequest friendRequest = this.friendRequestService.getById(id);
        return Result.ok(friendRequest);
    }

    /**
     * 新增数据
     *
     * @param friendRequest 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody FriendRequest friendRequest) {
        Boolean rst = this.friendRequestService.save(friendRequest);
        return Result.OK(rst);
    }

    /**
     * 修改数据
     *
     * @param friendRequest 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public Result update(@RequestBody FriendRequest friendRequest) {
        Boolean rst = this.friendRequestService.updateById(friendRequest);
        return Result.OK(rst);
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("idList") List<Long> idList) {
        boolean rst = this.friendRequestService.removeByIds(idList);
        return Result.ok(rst);
    }
}

